#include<bits/stdc++.h>
using namespace std;

bool cmp(const pair<int, int> a, const pair<int, int> b)
{
	return a.second < b.second;
}

int main()
{
	
	int n;
	while(cin>>n && n)
	{
		int x, y;
		vector<pair<int, int>> a;
		for(int i = 1;i <= n;i++)
		{
			cin>>x>>y;
			a.push_back({x, y});
		}
		sort(a.begin(), a.end(), cmp);
		
		int pre = 0, ans = 0;
		for(int i = 0;i < n;i++)
		{
			if(a[i].first >= pre)
			{
				pre = a[i].second;
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	cout<<endl;
	system("pause");
	return 0;
}

